package com.ala4.oxcafe.repository;

import com.ala4.oxcafe.boot.page.PageDomain;
import com.ala4.oxcafe.common.utils.object.ObjectUtil;
import com.ala4.oxcafe.common.utils.text.StrUtil;
import com.ala4.oxcafe.entity.WarrantyOrder;
import com.ala4.oxcafe.repository.mapper.WarrantyOrderMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 系统附件存储实体
 *
 * @author PING
 * @date 2025-03-25
 */
@Slf4j
@Repository
public class WarrantyOrderRepository extends ServiceImpl<WarrantyOrderMapper, WarrantyOrder> implements IService<WarrantyOrder> {

    private LambdaQueryWrapper<WarrantyOrder> queryParam(WarrantyOrder warrantyOrder) {

        LambdaQueryWrapper<WarrantyOrder> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.and(StrUtil.isNotEmpty(warrantyOrder.getSearchValue()), item -> {
            item.like(WarrantyOrder::getWarrantyNo, warrantyOrder.getSearchValue())
                    .or().like(WarrantyOrder::getCustomerName, warrantyOrder.getSearchValue());
        });
        queryWrapper.eq(ObjectUtil.isNotNull(warrantyOrder.getWarrantyNo()), WarrantyOrder::getWarrantyNo, warrantyOrder.getWarrantyNo());
        queryWrapper.eq(ObjectUtil.isNotNull(warrantyOrder.getCustomerPhone()), WarrantyOrder::getCustomerPhone, warrantyOrder.getCustomerPhone());

        return queryWrapper;
    }

    public IPage<WarrantyOrder> selectWarrantyOrderPage(PageDomain pageDomain, WarrantyOrder warrantyOrder) {

        return this.page(pageDomain.toPlusPage(), queryParam(warrantyOrder));
    }

    public List<WarrantyOrder> selectWarrantyOrderList(WarrantyOrder warrantyOrder) {
        return this.list(queryParam(warrantyOrder));
    }
}
